package com.gl.saasservice.adspace.controller;

import com.gl.framework.web.response.Result;
import com.gl.saasservice.adspace.service.SaasAdSpaceService;
import com.gl.saasservice.adspace.vo.SaasAdSpaceVO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Configuration;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

/**
 * 广告位置管理
 */

@Configuration
@Controller
@RequestMapping("/adspace")
public class SaasAdSpaceController {

    @Autowired
    private SaasAdSpaceService saasAdSpaceService;

    /**
     * 分页列表
     * @param pageNumber
     * @param pageSize
     * @param filter
     * @param sort
     * @return
     */
    @GetMapping(value = "/pages")
    @ResponseBody
    public Result page(
            @RequestParam(name = "pageNumber", required = true, defaultValue = "0") Integer pageNumber,
            @RequestParam(name = "pageSize", required = true, defaultValue = "10") Integer pageSize,
            SaasAdSpaceVO filter,
            @RequestParam(name = "sort", required = false) String sort) {
        return saasAdSpaceService.pages(pageNumber, pageSize, filter, sort);
    }


    /**
     * 新增
     *
     * @param vo
     * @return
     */
    @PostMapping()
    @ResponseBody
    public Result add(@RequestBody SaasAdSpaceVO vo) {
        return saasAdSpaceService.save(vo);
    }

    /**
     * 编辑
     */
    @PutMapping()
    @ResponseBody
    public Result update(@RequestBody SaasAdSpaceVO vo) {
        return saasAdSpaceService.save(vo);
    }

    /**
     * 删除
     */
    @DeleteMapping()
    @ResponseBody
    public Result delete(@RequestParam Long id) {
        return saasAdSpaceService.delete(id);
    }


    /**
     * 获取详情
     */
    @GetMapping(value = "/findAdSpaceById")
    @ResponseBody
    public Result findAdSpaceById(@RequestParam Long id) {
        return saasAdSpaceService.find(id);
    }

    /**
     * 获取所有广告位
     */
    @GetMapping(value = "/findAll")
    @ResponseBody
    public Result findAll(){
        return saasAdSpaceService.findAll();
    }


}
